import request from '@/utils/request'

/**
 * 消息API服务
 */

/**
 * 发送消息
 * @param {Object} data 消息数据
 * @returns {Promise} 请求Promise
 */
export function sendMessage(data) {
  return request({
    url: '/message/send',
    method: 'post',
    data
  })
}

/**
 * 获取两个设备之间的消息
 * @param {String} deviceId1 设备ID1
 * @param {String} deviceId2 设备ID2
 * @returns {Promise} 请求Promise
 */
export function getMessagesBetween(deviceId1, deviceId2) {
  return request({
    url: '/message/between',
    method: 'get',
    params: {
      deviceId1,
      deviceId2
    }
  })
}

/**
 * 获取未读消息数
 * @param {String} receiverId 接收者ID
 * @returns {Promise} 请求Promise
 */
export function getUnreadCount(receiverId) {
  return request({
    url: '/message/unread/count',
    method: 'get',
    params: {
      receiverId
    }
  })
}

/**
 * 标记消息为已读
 * @param {Number} messageId 消息ID
 * @returns {Promise} 请求Promise
 */
export function markAsRead(messageId) {
  return request({
    url: `/message/read/${messageId}`,
    method: 'put'
  })
}

/**
 * 批量标记消息为已读
 * @param {String} senderId 发送者ID
 * @param {String} receiverId 接收者ID
 * @returns {Promise} 请求Promise
 */
export function markAllAsRead(senderId, receiverId) {
  return request({
    url: '/message/read/all',
    method: 'put',
    params: {
      senderId,
      receiverId
    }
  })
}

/**
 * 更新消息状态
 * @param {Number} messageId 消息ID
 * @param {Number} status 状态
 * @returns {Promise} 请求Promise
 */
export function updateMessageStatus(messageId, status) {
  return request({
    url: '/message/status',
    method: 'put',
    params: {
      messageId,
      status
    }
  })
} 